//
//  LYDPopViewController.m
//  HAODE
//
//  Created by LiYinDi on 16/3/18.
//  Copyright © 2016年 reabam.com. All rights reserved.
//

#import "LYDPopViewController.h"
#import "UIImageView+WebCache.h"
#import "SpecColorDataModel.h"
#import "SpecSizeDataModel.h"
#import "FMDB.h"
#import "PlaceOrderSpecTableViewCell.h"
#import "specTableViewDataModel.h"
#import "HasSpecFmdbModel.h"
#import "HasSpecFmdbTool.h"
#import "UIViewExt.h"

@interface LYDPopViewController ()<PlaceOrderSpecCellDelegate>
{
    NSMutableArray *modelArray;
    NSString *colorSpecID;
    NSString *sizeSpecID;
    NSString *specName;
    NSString *userToken;
    NSString *specPrice;
    NSString *specInv;
    NSString *shopCartQty;
    NSString *specID;
    NSInteger subCellTag;
    NSInteger tagIndex;
    NSInteger colorIndex;
    NSInteger sizeIndex;
    NSMutableArray *specTableViewModelArray;
    CGFloat keyBoardHeight;
    
    NSInteger goodDetailClickCount;
}
@property(nonatomic,strong)FMDatabase *db;
@property (retain, nonatomic) UIAlertView* alt;
@end

@implementation LYDPopViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setAutoLayout];
    UIView *myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
    myToolBar.backgroundColor=jianpancolor;
    UIButton*btnDone=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
    [btnDone setTitle:@"确定" forState:UIControlStateNormal];
    [btnDone setTitleColor:jianpancolor1 forState:UIControlStateNormal];
    btnDone .titleLabel .font=[UIFont systemFontOfSize:17];
    [btnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:btnDone];
    myToolBar.alpha=alp;
    _countTextField.inputAccessoryView = myToolBar;

    if ([_countStr intValue]==0) {
        
        _countLabel.hidden=YES;
       _countBackGroundLabel.hidden=YES;
        _xLabel.hidden=YES;
        
    }
    else
    {
        
        _countLabel.text=[NSString stringWithFormat:@"×%@",_countStr];
        _count=_countStr;
        _countLabel.hidden=NO;
        _countBackGroundLabel.hidden=NO;
        _xLabel.hidden=NO;
    }

    modelArray=[NSMutableArray array];
    specTableViewModelArray=[NSMutableArray array];
    colorSpecID=@"";
    sizeSpecID=@"";
    specName=@"";
    userToken=@"";
    specPrice=@"";
    specInv=@"";
    specID=@"";
    shopCartQty=@"";
    tagIndex=0;
    goodDetailClickCount=0;
     [_topAlphaBtn setBackgroundColor: [Global parseColor:@"#66000000"]];
    _countView.layer.borderWidth=1;
    _countView.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1.0f] CGColor];
    
    _addBtn.layer.borderWidth=1;
    _addBtn.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1.0f] CGColor];
    
//    [_productImageView setImageWithURL:[NSURL URLWithString:_productURL]];
     [_productImageView setImageWithURL:[NSURL URLWithString:_productURL] placeholderImage:[UIImage imageNamed:@"zhengfangxing"]];
    _productImageView.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1] CGColor];
    _productImageView.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1] CGColor];
     _productImageView.layer.borderWidth= 0.5f;
    
     _productNameLabel.text=_productNameStr;

    
    [_selectedGoodDetailBtn addTarget:self action:@selector(selectedGoodDetailBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    
    [self requestProductDetail:_itemIDStr];

    
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if (ScreenHeight<=667) {
    self.view.bottom=ScreenHeight-256+_specParentView.height-_countParentView.bottom+_confirmBtn.height;
    }
    return YES;
}
-(void)OnTapDone
{
    if (ScreenHeight<=667) {
        self.view.bottom=ScreenHeight;
    }
    [_countTextField resignFirstResponder];
}
- (IBAction)subtractCountBtnClick:(id)sender {
    
    NSString *countStr=_countTextField.text;
    countStr=[NSString stringWithFormat:@"%d",[countStr intValue]-1];
    if ([countStr intValue]>=1) {
        _countTextField.text=countStr;
    }
}

- (IBAction)addCountBtnClick:(id)sender {
    _countTextField.text=[NSString stringWithFormat:@"%d",[_countTextField.text intValue]+1];
}

-(void)requestProductDetail:(NSString *)itemIdStr
{
    modelArray=[NSMutableArray array];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    userToken=Token;
    NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
    [params setObject:Token forKey:@"tokenId"];
    [params setObject:itemIdStr forKey:@"itemId"];
    [params setObject:@"Y" forKey:@"isShopCart"];
    [HttpRequest requestData:@"Product/GetProductDetail" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
       NSLog(@"GetProductDetail====%@",severDataDict.dataDict);
        if (isSuccess) {
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                
                [Global hideProgressHUDInternal:self.view];
               
                NSArray *dataArray=severDataDict.dataDict[@"itemColours"];
                for (NSDictionary *dic in dataArray) {
                    SpecColorDataModel *dataModel=[SpecColorDataModel dataModelWithDict:dic];
                    [modelArray addObject:dataModel];
                    
                }

                [self setColor];
                if ([_typeString isEqualToString:@"SCANCASHIER"]) {
                    if ([[severDataDict.dataDict objectForKey:@"shopCartQty"] intValue]==0) {
                        _countLabel.hidden=YES;
                        _countBackGroundLabel.hidden=YES;
                        _xLabel.hidden=YES;
                        
                    }
                    else
                    {
                        _countLabel.text=[NSString stringWithFormat:@"×%@",[severDataDict.dataDict objectForKey:@"shopCartQty"]];
                        _countLabel.hidden=NO;
                        _countBackGroundLabel.hidden=NO;
                        _xLabel.hidden=NO;
                    }

                }else{
                    
                }
             }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
                
                
            }
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            [Global showTextHudSub:severDataDict.resultStr view:self.view];
        }
    }];
    

}
-(void)setColor
{
    for (UIView *v in _colorView.subviews ) {
        [v removeFromSuperview];
    }
    
    UILabel *colorTag=[[UILabel alloc] initWithFrame:CGRectMake(16, 20, 100, 14)];
    colorTag.text=@"颜色";
    colorTag.tag=1000;
    [colorTag setFont:[UIFont systemFontOfSize:14]];
    colorTag.textColor=[UIColor colorWithRed:51.0/255.0 green:51.0/255.0 blue:51.0/255.0 alpha:1.0f];
    [_colorView addSubview:colorTag];
    
    UIImageView *lineImageView=[[UIImageView alloc] initWithFrame:CGRectMake(10, 44,ScreenWidth-20 , 1)];
    lineImageView.tag=1000;
    [lineImageView setImage:[UIImage imageNamed:@"hengxian.png"] ];
    [_colorView addSubview:lineImageView];

    for (int i=0; i<modelArray.count; i++) {
        SpecColorDataModel *dataModel=modelArray[i];
        UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
        CGRect rect=button.frame;
        rect.size.height=33;
        rect.size.width=(ScreenWidth-48)/3;
        rect.origin.x=13+((ScreenWidth-48)/3)*(i%3)+(i%3)*11;
        rect.origin.y=56+40*(i/3);
        button.frame=rect;
        button.tag=i;
        [button setBackgroundColor:[UIColor colorWithRed:244.0f/255.0f green:244.0f/255.0f blue:244.0f/255.0f alpha:1.0f]];
        
        
        button.titleLabel.font = [UIFont systemFontOfSize: 14.0];
        [button setTitle:dataModel.colourName forState:UIControlStateNormal];
        [button setTitleColor:[UIColor colorWithRed:51.0f/255.0f green:51.0f/255.0f blue:51.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
        
        if (i==tagIndex) {
             [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [button setBackgroundColor:[UIColor colorWithRed:90.0f/255.0f green:130.0f/255.0f blue:26.0f/255.0f alpha:1.0]];
            colorSpecID=dataModel.colourId;
            specName=dataModel.colourName;
            specInv=dataModel.specInv;
            specPrice=dataModel.specPrice;
            specID=dataModel.specId;
            _priceLabel.text=[NSString stringWithFormat:@"¥ %@",specPrice];
            
            shopCartQty=dataModel.shopCartQty;
            NSString *str=[NSString stringWithFormat:@"库存 %@",specInv];
            NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:str];
            [attriString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:153.0/255.0 green:153.0/255.0 blue:153.0/255.0 alpha:1.0] range:NSMakeRange(0, 2)];
            
            _stockLabel.attributedText=attriString;

            
        }
        
        [button addTarget:self action:@selector(colorButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [_colorView addSubview:button];
        
 
        if (i==modelArray.count-1) {
            
           CGFloat height=button.frame.origin.y+button.frame.size.height+11;
            
            
            [_colorView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(_specScrollContentView.mas_top);
                make.bottom.equalTo(_specScrollContentView.mas_top).with.offset(height);
                make.left.equalTo(_specScrollContentView.mas_left);
                make.right.equalTo(_specScrollContentView.mas_right);
                
            }];
            
            [self setSize:0];
        }
        
        
    }
}
-(void)colorButtonClick:(UIButton *)sender
{
    for (UIButton *btn in _colorView.subviews ) {
        if (btn.tag!=1000) {
            
        
         [btn setBackgroundColor:[UIColor colorWithRed:244.0f/255.0f green:244.0f/255.0f blue:244.0f/255.0f alpha:1.0]];
        [btn setTitleColor:[UIColor colorWithRed:51.0f/255.0f green:51.0f/255.0f blue:51.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
        }
    }
    [sender setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [sender setBackgroundColor:[UIColor colorWithRed:90.0f/255.0f green:130.0f/255.0f blue:26.0f/255.0f alpha:1.0]];
     SpecColorDataModel *colorModel=modelArray[sender.tag];
    colorIndex=sender.tag;
    colorSpecID=colorModel.colourId;
    specName=colorModel.colourName;
    specID=colorModel.specId;
     specInv=colorModel.specInv;
    specPrice=colorModel.specPrice;
     shopCartQty=colorModel.shopCartQty;
    _priceLabel.text=[NSString stringWithFormat:@"¥ %@",specPrice];
//    NSLog(@"colorModel.specInv==%@",colorModel.specInv);
//    NSLog(@"specInv pp==%@",specInv);
    if (colorModel.sizeModelArray.count>0) {
//       NSLog(@"olorModel.sizeModelArraypp==%@",colorModel.sizeModelArray);
    SpecSizeDataModel *sizeModel=colorModel.sizeModelArray[0];
    sizeSpecID=sizeModel.sizeId;
    specName=[NSString stringWithFormat:@"%@%@",specName,sizeModel.sizeName];
    specInv=sizeModel.specInv;
    specPrice=sizeModel.specPrice;
    shopCartQty=colorModel.shopCartQty;
    _priceLabel.text=[NSString stringWithFormat:@"¥ %@",specPrice];
    specID=sizeModel.specId;
    [self setSize:sender.tag];
    }
    tagIndex=sender.tag;
    NSLog(@"%ld",sender.tag);
    NSString *str=[NSString stringWithFormat:@"库存 %@",specInv];
    NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:str];
    [attriString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:153.0/255.0 green:153.0/255.0 blue:153.0/255.0 alpha:1.0] range:NSMakeRange(0, 2)];
    
    _stockLabel.attributedText=attriString;
    

}

-(void)setSize:(NSInteger)senderTag
{
    for (UIView *v in _sizeView.subviews ) {
        [v removeFromSuperview];
    }
    SpecColorDataModel *colorModel=modelArray[senderTag];
    
    NSMutableArray   *sizeModelArray=colorModel.sizeModelArray ;
    
//    NSLog(@"sizeModelArraymmmmm====%@",sizeModelArray);
    if (sizeModelArray.count>0) {
        
   
    UILabel *colorTag=[[UILabel alloc] initWithFrame:CGRectMake(16, 0+24, 100, 14)];
    colorTag.tag=1000;
    colorTag.text=@"尺码";
    [colorTag setFont:[UIFont systemFontOfSize:14]];
    colorTag.textColor=[UIColor colorWithRed:51.0/255.0 green:51.0/255.0 blue:51.0/255.0 alpha:1.0f];
    [_sizeView addSubview:colorTag];
    
    UIImageView *lineImageView=[[UIImageView alloc] initWithFrame:CGRectMake(10, 24+24, ScreenWidth-20, 1)];
      lineImageView.tag=1000;
    [lineImageView setImage:[UIImage imageNamed:@"hengxian.png"] ];
    [_sizeView addSubview:lineImageView];
    
  
    for (int i=0; i<sizeModelArray.count; i++) {
        SpecSizeDataModel *sizeModel=sizeModelArray[i];
        
        UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
        CGRect rect=button.frame;
        rect.size.height=32;
        
        rect.size.width=(ScreenWidth-59)/4;
        rect.origin.x=13+((ScreenWidth-59)/4)*(i%4)+(i%4)*10;
//        rect.size.width=ScreenWidth/4.5;
//        rect.origin.x=10+(ScreenWidth/4.2)*(i%4);
        rect.origin.y=36+24+40*(i/4);
        button.frame=rect;
        button.tag=i;
        [button setBackgroundColor:[UIColor colorWithRed:244.0f/255.0f green:244.0f/255.0f blue:244.0f/255.0f alpha:1.0f]];
       
        
        button.titleLabel.font = [UIFont systemFontOfSize: 14.0];
        [button setTitle:sizeModel.sizeName forState:UIControlStateNormal];
        [button setTitleColor:[UIColor colorWithRed:51.0f/255.0f green:51.0f/255.0f blue:51.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
        
        [button addTarget:self action:@selector(sizeButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [_sizeView addSubview:button];
        
        if (i==0) {
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [button setBackgroundColor:[UIColor colorWithRed:90.0f/255.0f green:130.0f/255.0f blue:26.0f/255.0f alpha:1.0]];
            sizeSpecID=sizeModel.sizeId;
            specName=[NSString stringWithFormat:@"%@%@",colorModel.colourName,sizeModel.sizeName];
            specInv=sizeModel.specInv;
            specPrice=sizeModel.specPrice;
            shopCartQty=sizeModel.shopCartQty;
            if (colorModel.specId.length>0 ) {
                specID=colorModel.specId;
            }
            else
            {
                specID=sizeModel.specId;
            }
            
            _priceLabel.text=[NSString stringWithFormat:@"¥ %@",specPrice];
            
            NSString *str=[NSString stringWithFormat:@"库存 %@",specInv];
            NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:str];
            [attriString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:153.0/255.0 green:153.0/255.0 blue:153.0/255.0 alpha:1.0] range:NSMakeRange(0, 2)];
            
            _stockLabel.attributedText=attriString;

        }

        if (i==sizeModelArray.count-1) {
            
           CGFloat height=button.frame.origin.y+button.frame.size.height+11;
            [_sizeView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(_colorView.mas_bottom);
                make.bottom.equalTo(_colorView.mas_bottom).with.offset(height);
                make.left.equalTo(_specScrollContentView.mas_left);
                make.right.equalTo(_specScrollContentView.mas_right);
                
            }];

        }
        }
    }
}
-(void)sizeButtonClick:(UIButton *)sender
{
    sizeIndex=sender.tag;
    for (UIButton *btn in _sizeView.subviews ) {
        if (btn.tag!=1000) {
         [btn setBackgroundColor:[UIColor colorWithRed:244.0f/255.0f green:244.0f/255.0f blue:244.0f/255.0f alpha:1.0f]];
         [btn setTitleColor:[UIColor colorWithRed:51.0f/255.0f green:51.0f/255.0f blue:51.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
        }
    }
    [sender setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [sender setBackgroundColor:[UIColor colorWithRed:90.0f/255.0f green:130.0f/255.0f blue:26.0f/255.0f alpha:1.0]];
     SpecColorDataModel *colorModel=modelArray[colorIndex];
//    NSLog(@"colorModel.sizeModelArray==%@",colorModel.sizeModelArray);
    SpecSizeDataModel *sizeModel=colorModel.sizeModelArray[sender.tag];
    sizeSpecID=sizeModel.sizeId;
    specName=[NSString stringWithFormat:@"%@%@",colorModel.colourName,sizeModel.sizeName];
    specInv=sizeModel.specInv;
    specPrice=sizeModel.specPrice;
    shopCartQty=sizeModel.shopCartQty;
    if (colorModel.specId.length>0 ) {
        specID=colorModel.specId;
    }
    else
    {
        specID=sizeModel.specId;
    }
    _priceLabel.text= [NSString stringWithFormat:@"¥ %@",specPrice];
    NSString *str=[NSString stringWithFormat:@"库存 %@",specInv];
    NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:str];
    [attriString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:153.0/255.0 green:153.0/255.0 blue:153.0/255.0 alpha:1.0] range:NSMakeRange(0, 2)];
    
    _stockLabel.attributedText=attriString;
}
-(void)selectedGoodDetailBtnClick
{
   
    if (goodDetailClickCount%2==0) {
        [_selectedGoodImage setImage:[UIImage imageNamed:@"shouqi_shang"]];
       [self getSpectDataFromDB];
    }
    else{
        [_selectedGoodImage setImage:[UIImage imageNamed:@"zhankai"]];
        [specTableViewModelArray removeAllObjects];
        _specTableView.hidden=YES;
        _specScrollView.hidden=NO;
        [_selectedGoodDetailBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@44);
            make.left.equalTo(_specParentView.mas_left);
            make.right.equalTo(_specParentView.mas_right);
            make.top.equalTo(_specScrollContentView.mas_bottom).with.offset(-40);
            
        }];
        
        [_specTableView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@0);
            make.left.equalTo(_specParentView.mas_left);
            make.right.equalTo(_specParentView.mas_right);
            make.top.equalTo(_specParentView.mas_bottom);
        }];
 
    }
    goodDetailClickCount++;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return specTableViewModelArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * const  ResultTableViewCellIdentifier = @"PlaceOrderSpecTableViewCell";
    PlaceOrderSpecTableViewCell *cell=( PlaceOrderSpecTableViewCell *)[tableView dequeueReusableCellWithIdentifier: ResultTableViewCellIdentifier];
    if (cell==nil) {
        NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"PlaceOrderSpecTableViewCell" owner:self options:nil];
        cell = [array objectAtIndex:0];
    }
  
    cell.delegate=self;
    cell.addCountBtn.tag=indexPath.row;
    cell.subtractCountBtn.tag=indexPath.row;
    //  cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame] ;
    cell.selectedBackgroundView.backgroundColor = [UIColor clearColor];
    
     if ([_typeString isEqualToString:@"SCANCASHIER"]) {
         specTableViewDataModel *model=specTableViewModelArray[indexPath.row];
        cell.nameLabel.text= model.specName;
         
         cell.contentLabel.text=[NSString stringWithFormat:@"¥%0.02f  库存 %d",[model.specPrice floatValue],[model.specInv intValue]];
         cell.countTextField.text=[NSString stringWithFormat:@" %d", [model.shopCartQty intValue]];
     }else{
    specTableViewDataModel *model=specTableViewModelArray[indexPath.row];
   
    cell.nameLabel.text= model.specName;
    cell.contentLabel.text=[NSString stringWithFormat:@"¥%0.02f  库存 %d",[model.specPrice floatValue],[model.specStock intValue]];
    cell.countTextField.text=[NSString stringWithFormat:@" %d", [model.specCount intValue]];
     }
    
    return cell;
}
#pragma mark PlaceOrderSpecTableViewCellDelegate
-(void)SpecCellAddCountBtnClick:(NSUInteger)tag parentIndex:(NSUInteger)parentIndex
{
    specTableViewDataModel *specModel=specTableViewModelArray[tag];
    HasSpecFmdbModel *model=[HasSpecFmdbModel modalWith:userToken itemId:_itemIDStr itemCode:@"" colorSpecID:specModel.colorSpecID sizeSpecID:specModel.sizeSpecID specName:@"" specPrice:@"" specStock:@"" specCount:@"" typeString:_typeString specID:@""];
    if ([_typeString isEqualToString:@"WhsOut"]||[_typeString isEqualToString:@"PlaceOrder"]||[_typeString isEqualToString:@"SCANCASHIER"]) {
        
        if ([_typeString isEqualToString:@"SCANCASHIER"]) {
            if ([specModel.shopCartQty  intValue]<[ specModel.specInv intValue]) {
               _addTypeString=@"addTypeString";
                 subCellTag=tag;
                NSString *oriCount=[NSString stringWithFormat:@"%d",[specModel.shopCartQty intValue]];
                oriCount=[NSString stringWithFormat:@"%d",[oriCount intValue]+1];
                [self ShopCartMerge:specModel.itemID :specModel.specId :oriCount];

            }else{
                  [self showAlertMessage:@"已超出商品库存量"];
                _addTypeString=@"addTypeString";
                subCellTag=tag;
                NSString *oriCount=[NSString stringWithFormat:@"%d",[specModel.shopCartQty intValue]];
                oriCount=[NSString stringWithFormat:@"%d",[oriCount intValue]+1];
                [self ShopCartMerge:specModel.itemID :specModel.specId :oriCount];
                
            }
        }else{
        BOOL suc= [HasSpecFmdbTool modifySpecCountWithLimit:model countText:@"1"];
        if (suc) {
            NSString *oriCount=[NSString stringWithFormat:@"%d",[specModel.specCount intValue]];
            oriCount=[NSString stringWithFormat:@"%d",[oriCount intValue]+1];
            _countLabel.text=[NSString stringWithFormat:@"×%d",_count.intValue+1];
            _count=[NSString stringWithFormat:@"%d",_count.intValue+1];
            specModel.specCount=oriCount;
            [specTableViewModelArray replaceObjectAtIndex:tag withObject:specModel];
            
            NSIndexPath *tmpIndexpath=[NSIndexPath indexPathForRow:tag inSection:0];
            [_specTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:tmpIndexpath, nil]  withRowAnimation:UITableViewRowAnimationFade];
            
        }
        else
        {
            UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"已超商品库存量" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
            
        }
        }
    }
    else{
        BOOL suc= [HasSpecFmdbTool modifySpecCountNoLimit:model countText:@"1"];
        if (suc) {
            NSString *oriCount=[NSString stringWithFormat:@"%d",[specModel.specCount intValue]];
            oriCount=[NSString stringWithFormat:@"%d",[oriCount intValue]+1];
            specModel.specCount=oriCount;
            _countLabel.text=[NSString stringWithFormat:@"×%d",_count.intValue+1];
            _count=[NSString stringWithFormat:@"%d",_count.intValue+1];
       
            [specTableViewModelArray replaceObjectAtIndex:tag withObject:specModel];
            
            NSIndexPath *tmpIndexpath=[NSIndexPath indexPathForRow:tag inSection:0];
            [_specTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:tmpIndexpath, nil]  withRowAnimation:UITableViewRowAnimationFade];
        }
    }
}
-(void)SpecCellSubtractCountBtnClick:(NSUInteger)tag parentIndex:(NSUInteger)parentIndex
{
    specTableViewDataModel *specModel=specTableViewModelArray[tag];
    if ([self.typeString isEqualToString:@"SCANCASHIER"]) {
         subCellTag=tag;
        
        _addTypeString=@"SubtractString";
        NSString *oriCount=[NSString stringWithFormat:@"%d",[specModel.shopCartQty intValue]];
        oriCount=[NSString stringWithFormat:@"%d",[oriCount intValue]-1];
        [self ShopCartMerge:specModel.itemID :specModel.specId :oriCount];

    }else{
    
    NSString *oriCount=[NSString stringWithFormat:@"%d",[specModel.specCount intValue]];
    oriCount=[NSString stringWithFormat:@"%d",[oriCount intValue]-1];
    if (oriCount.intValue>0) {
        HasSpecFmdbModel *model=[HasSpecFmdbModel modalWith:userToken itemId:_itemIDStr itemCode:@"" colorSpecID:specModel.colorSpecID sizeSpecID:specModel.sizeSpecID specName:@"" specPrice:@"" specStock:@"" specCount:@"" typeString:_typeString specID:@""];
        BOOL suc= [HasSpecFmdbTool modifySpecCountNoLimit:model countText:@"-1"];
        if (suc) {
            
            specModel.specCount=oriCount;
            [specTableViewModelArray replaceObjectAtIndex:tag withObject:specModel];
           
            _countLabel.text=[NSString stringWithFormat:@"×%d",_count.intValue-1];
            _count=[NSString stringWithFormat:@"%d",_count.intValue-1];
            NSIndexPath *tmpIndexpath=[NSIndexPath indexPathForRow:tag inSection:0];
            [_specTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:tmpIndexpath, nil]  withRowAnimation:UITableViewRowAnimationFade];
        }
        
    }
    else  if ([oriCount intValue]==0)
    {
        NSString *sqlStr=[NSString stringWithFormat:@"DELETE FROM t_Spec WHERE userToken = '%@' AND itemID = '%@' AND colorSpecID = '%@' AND sizeSpecID = '%@' AND typeString = '%@';",userToken, _itemIDStr,specModel.colorSpecID,specModel.sizeSpecID,_typeString];
        [HasSpecFmdbTool deleteData:sqlStr];
        
        [specTableViewModelArray removeObjectAtIndex:tag];
        _countLabel.text=[NSString stringWithFormat:@"×%d",_count.intValue-1];
        _count=[NSString stringWithFormat:@"%d",_count.intValue-1];
        [_specTableView reloadData];
    }
    }

}
- (IBAction)alphaBtnClick:(id)sender {
    if ([self.delegate respondsToSelector:@selector(closePop: )]) {
         if ([[Global getType] isEqualToString:@"SCANCASHIER"]) {
             [self.delegate closePop:_countLabel.text  ];
         }else{
             [self.delegate closePop:_count];
         }
    }
    [self dismiss];
}
- (void)show
{
    
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    self.view.frame = CGRectMake(0,
                                  0,
                                  [UIScreen mainScreen].bounds.size.width,
                                  [UIScreen mainScreen].bounds.size.height);
    
   [window addSubview:self.view];
}
- (void)dismiss
{
    [self.view removeFromSuperview];
    [self removeFromParentViewController];
    
}
-(void)ShopCartMerge:(NSString *)pidStr :(NSString *)specIdStr :(NSString *)ySelQty {
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setValue:userToken forKey:@"tokenId"];
    [params setValue:_itemIDStr forKey:@"itemId"];
    [params setValue:specIdStr forKey:@"specId"];
    [params setValue:ySelQty  forKey:@"quantity"];
     NSLog(@"SCANrequestItemDetail====%@",params);
    [HttpRequest requestData:@"Business/ShopCart/Merge" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                NSLog(@"SCANrequestItemDetail====%@",severDataDict.dataDict);
                [self requestProductDetail:_itemIDStr];
                
                if ([_addTypeString isEqualToString:@"addTypeString"]) {
                    specTableViewDataModel *model=specTableViewModelArray[subCellTag];
                    NSString *oriCount=[NSString stringWithFormat:@"%d",[model.shopCartQty intValue]];
                   oriCount=[NSString stringWithFormat:@"%d",[oriCount intValue]+1];
                    model.shopCartQty=oriCount;
                    [specTableViewModelArray replaceObjectAtIndex:subCellTag withObject:model];
                    NSIndexPath *tmpIndexpath=[NSIndexPath indexPathForRow:subCellTag inSection:0];
                    [_specTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:tmpIndexpath, nil]  withRowAnimation:UITableViewRowAnimationFade];
                }else if ([_addTypeString isEqualToString:@"SubtractString"]){
                    specTableViewDataModel *model=specTableViewModelArray[subCellTag];
                    NSString *oriCount=[NSString stringWithFormat:@"%d",[model.shopCartQty intValue]];
                    oriCount=[NSString stringWithFormat:@"%d",[oriCount intValue]-1];
                    model.shopCartQty=oriCount;
                    [specTableViewModelArray replaceObjectAtIndex:subCellTag withObject:model];
                    NSIndexPath *tmpIndexpath=[NSIndexPath indexPathForRow:subCellTag inSection:0];
                    [_specTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:tmpIndexpath, nil]  withRowAnimation:UITableViewRowAnimationFade];
                
                }
                shopCartQty=[NSString stringWithFormat:@"%@",[severDataDict.dataDict objectForKey:@"cItemQty"]];
                _countLabel.text=[NSString stringWithFormat:@"×%@",[severDataDict.dataDict objectForKey:@"cItemTotalQty"]];
                _countLabel.hidden=NO;
                _countBackGroundLabel.hidden=NO;
                _xLabel.hidden=NO;
                [Global showTextHudSub:@"添加成功" view:self.view];
                

            }else
            {
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
                
            }
        }
        else
        {
            
            [Global showTextHudSub:severDataDict.resultStr view:self.view];
        }
    }];
}

- (IBAction)addBtnClick:(id)sender {
    //先在表中查询有没有相同的元素，如果有，做修改操作
    NSLog(@"SCANrequestItemDetail====%@",shopCartQty);
     NSLog(@"SCANrequestItemDetail====%@",specInv);
    
    _addTypeString=@"";
    if ([_typeString isEqualToString:@"SCANCASHIER"]) {
            
        if ([shopCartQty intValue]+[_countTextField.text intValue]<=[specInv intValue]) {
            NSString *oriCount=[NSString stringWithFormat:@"%d",[shopCartQty intValue]];
            oriCount=[NSString stringWithFormat:@"%d",[shopCartQty intValue]+[_countTextField.text intValue]];
            [self ShopCartMerge:_itemIDStr :specID :oriCount];
        }else{
            
             [self showAlertMessage:@"已超出商品库存量"];
            
            NSString *oriCount=[NSString stringWithFormat:@"%d",[shopCartQty intValue]];
            oriCount=[NSString stringWithFormat:@"%d",[shopCartQty intValue]+[_countTextField.text intValue]];
            [self ShopCartMerge:_itemIDStr :specID :oriCount];

            
        }

}else{
    
    
    
    
    HasSpecFmdbModel *model=[HasSpecFmdbModel modalWith:userToken itemId:_itemIDStr itemCode:_itemCodeStr colorSpecID:colorSpecID sizeSpecID:sizeSpecID specName:specName specPrice:specPrice specStock:specInv specCount:_countTextField.text typeString:_typeString specID:specID];
    if ([_typeString isEqualToString:@"WhsOut"]||[_typeString isEqualToString:@"PlaceOrder"]||[_typeString isEqualToString:@"SCANCASHIER"]) {
        
        BOOL suc= [HasSpecFmdbTool modifySpecCountWithLimit:model countText:_countTextField.text];
        if (suc) {
            
           
            _countLabel.text=[NSString stringWithFormat:@"×%d",[_count intValue]+[_countTextField.text intValue]];
             _count=[NSString stringWithFormat:@"%d",[_count intValue]+[_countTextField.text intValue]];
            _countLabel.hidden=NO;
            _countBackGroundLabel.hidden=NO;
            _xLabel.hidden=NO;
            [Global showTextHudSub:@"添加成功" view:self.view];
        }
//        else
//        {
//            UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"已超商品库存量" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
//            [alert show];
//        }
    }
    else
    {
        BOOL suc= [HasSpecFmdbTool modifySpecCountNoLimit:model countText:_countTextField.text];
        if (suc) {
            _countLabel.text=[NSString stringWithFormat:@"×%d",[_count intValue]+[_countTextField.text intValue]];
            _count=[NSString stringWithFormat:@"%d",[_count intValue]+[_countTextField.text intValue]];
           
            _countLabel.hidden=NO;
            _countBackGroundLabel.hidden=NO;
            _xLabel.hidden=NO;

            [Global showTextHudSub:@"添加成功" view:self.view];
        }
//        else
//        {
//            UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"已超商品库存量" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
//            [alert show];
//        }
        
    }
   
    }
    
    
    
    
}

-(void )getSpectDataFromDB
{
   
    if ([_typeString isEqualToString:@"SCANCASHIER"]) {
        
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        NSString* Token = [user objectForKey:@"tokenId"];
        userToken=Token;
        //    [Global showIndeterminateHud:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:Token forKey:@"tokenId"];
        [params setObject:_itemIDStr forKey:@"itemId"];
        [params setObject:@"Y" forKey:@"isShopCart"];
        [HttpRequest requestData:@"Product/GetProductDetail" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            NSLog(@"GetProductDetail====%@",severDataDict.dataDict);
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    
                    [Global hideProgressHUDInternal:self.view];
                    
                    NSMutableArray *mArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"specList"]];
                    for (NSDictionary* dicc in mArray )
                    {
                        specTableViewDataModel *model = nil;
                        model=[specTableViewDataModel mj_objectWithKeyValues:dicc];
                        if(model != nil)
                        [specTableViewModelArray addObject:model];
                    }

                    [self animationsView];
                   
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:severDataDict.resultStr view:self.view];
            }
        }];

        
        
    
    }else{

    NSString *sqlStr=[NSString stringWithFormat:@"SELECT * FROM t_Spec WHERE userToken = '%@' AND itemID = '%@' AND typeString = '%@';" ,userToken,_itemIDStr,_typeString];
          NSLog(@"specTableViewModelArray%@",sqlStr);
//        NSLog(@"")
    NSArray *array=[HasSpecFmdbTool queryData:sqlStr];
   [specTableViewModelArray addObjectsFromArray:array];
    [self animationsView];

    }
    
}
-(void)animationsView{

    [_specTableView reloadData];
    _specTableView.hidden=NO;
    _specScrollView.hidden=YES;

   [UIView animateWithDuration:0.2 animations:^{
        [_selectedGoodDetailBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@41);
            make.left.equalTo(_specParentView.mas_left);
            make.right.equalTo(_specParentView.mas_right);
            make.top.equalTo(_specParentView.mas_top);
            
        }];
        
        
        [_specTableView mas_remakeConstraints:^(MASConstraintMaker *make) {
            //            make.height.equalTo(@0);
            make.left.equalTo(_specParentView.mas_left);
            make.right.equalTo(_specParentView.mas_right);
            make.top.equalTo(_selectedGoodDetailBtn.mas_bottom);
            make.bottom.equalTo(_specParentView.mas_bottom).with.offset(0);
        }];
        
        
    } completion:^(BOOL finished){
        
    }];
    

}

-(void)setAutoLayout
{
    [_confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view.mas_bottom);
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.height.equalTo(@48);
        
    }];

    [_topAlphaBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top);
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.height.equalTo(@74);
        
    }];
    [_cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_topAlphaBtn.mas_bottom);
        make.width.equalTo(@80);
        make.right.equalTo(self.view.mas_right);
        make.height.equalTo(@40);
        
    }];
    [_parentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_topAlphaBtn.mas_bottom);
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.bottom.equalTo(self.view.mas_bottom);
        
    }];
    
    [_productImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_parentView.mas_top).with.offset(24);
        make.left.equalTo(_parentView.mas_left).with.offset(10);
        make.width.equalTo(@82);
        make.height.equalTo(@82);
        
    }];
    [_countBackGroundLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_parentView.mas_top).with.offset(24);
        make.left.equalTo(_parentView.mas_left).with.offset(10);
        make.width.equalTo(@82);
        make.height.equalTo(@82);
        
    }];
    [_xLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_productImageView.mas_bottom) ;
        make.left.equalTo(_productImageView.mas_left).with.offset(5) ;
        make.width.equalTo(@10);
        make.height.equalTo(@15);
        
    }];
    [_countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_parentView.mas_top).with.offset(24);
        make.left.equalTo(_parentView.mas_left).with.offset(10);
        make.width.equalTo(@82);
        make.height.equalTo(@82);
        
    }];


    
    [_productNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_productImageView.mas_top).with.offset(5) ;
        make.left.equalTo(_productImageView.mas_right).with.offset(12);
        make.right.equalTo(self.view.mas_right);
        make.bottom.equalTo(_priceLabel.mas_top).with.offset(-2);
        
    }];
    
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_productNameLabel.mas_bottom).with.offset(2) ;
        make.left.equalTo(_productNameLabel.mas_left) ;
        make.right.equalTo(self.view.mas_right);
        make.height.equalTo(@13);
        
    }];
    [_stockLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_productImageView.mas_bottom).with.offset(-5) ;
        make.left.equalTo(_productNameLabel.mas_left) ;
        make.right.equalTo(self.view.mas_right);
        make.height.equalTo(@18);
        
    }];
    
    [_productImageBottomLineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_productImageView.mas_bottom).with.offset(20);
        make.left.equalTo(_parentView.mas_left).with.offset(10);
        make.right.equalTo(_parentView.mas_right).with.offset(-10);
        make.height.equalTo(@0.5);
        
    }];
   
    [_specParentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_productImageBottomLineLabel.mas_bottom)  ;
        make.left.equalTo(_parentView.mas_left);
        make.right.equalTo(_parentView.mas_right);
        make.bottom.equalTo(_confirmBtn.mas_top);
    }];
   
   
    [_specScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_specParentView.mas_top)  ;
        make.left.equalTo(_specParentView.mas_left);
        make.right.equalTo(_specParentView.mas_right);
        make.bottom.equalTo(_specParentView.mas_bottom );
    }];
   

    [_specScrollContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(_specScrollView);
        make.width.equalTo(_specScrollView);
    }];
    [_colorView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@0);
        make.left.equalTo(_specScrollContentView.mas_left);
        make.right.equalTo(_specScrollContentView.mas_right);
        make.top.equalTo(_specScrollContentView.mas_top);
    }];
    [_sizeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@0);
        make.left.equalTo(_specScrollContentView.mas_left);
        make.right.equalTo(_specScrollContentView.mas_right);
        make.top.equalTo(_colorView.mas_bottom);
    }];
    [_countParentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@67);
        make.left.equalTo(_specScrollContentView.mas_left);
        make.right.equalTo(_specScrollContentView.mas_right);
        make.top.equalTo(_sizeView.mas_bottom);
        make.bottom.equalTo(_specScrollContentView.mas_bottom);
    }];
    [_countParentTopLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_countParentView.mas_top) ;
        
        make.right.equalTo(_countParentView.mas_right).with.offset(-10);
        make.height.equalTo(@0.5);
        make.left.equalTo(_countParentView.mas_left).with.offset(10);
        
    }];
    [_countParentBottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_countParentView.mas_bottom) ;
        
        make.right.equalTo(_countParentView.mas_right).with.offset(-10);
        make.height.equalTo(@0.5);
        make.left.equalTo(_countParentView.mas_left).with.offset(10);
        
    }];


    [_addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_countParentView.mas_top).with.offset(16.5);
        
        make.right.equalTo(_countParentView.mas_right).with.offset(-10);
        make.height.equalTo(@36);
        make.width.equalTo(@90);
        
    }];
    
    [_countView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_countParentView.mas_left).with.offset(50);
        
        make.right.equalTo(_addBtn.mas_left).with.offset(-15);
        make.height.equalTo(@34);
        make.centerY.equalTo(_countParentView.mas_centerY);
        
    }];
    [_subtractCountBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_countView.mas_top) ;
          make.bottom.equalTo(_countView.mas_bottom) ;
        make.left.equalTo(_countView.mas_left) ;
        
        make.width.equalTo(@34);
        
    }];
    [_addCountBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_countView.mas_top) ;
        make.bottom.equalTo(_countView.mas_bottom) ;
        make.right.equalTo(_countView.mas_right) ;
        
        make.width.equalTo(@34);
        
    }];
    
    [_countTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_countView.mas_top) ;
        make.bottom.equalTo(_countView.mas_bottom) ;
        make.right.equalTo(_addCountBtn.mas_left) ;
        
       make.left.equalTo(_subtractCountBtn.mas_right) ;
        
    }];

    [_specScrollContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_countParentView.mas_bottom).with.offset(40);
    }];
  
    [_selectedGoodDetailBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@44);
        make.left.equalTo(_specParentView.mas_left);
        make.right.equalTo(_specParentView.mas_right);
        make.top.equalTo(_specScrollContentView.mas_bottom).with.offset(-40);
    }];
    [_selectedGoodImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@30);
         make.width.equalTo(@30);
        
        make.right.equalTo(_selectedGoodDetailBtn.mas_right).with.offset(-10);
        make.centerY.equalTo(_selectedGoodDetailBtn.mas_centerY);
        
    }];
    [_selectedGoodLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@15);
        make.width.equalTo(@113);
        
        make.right.equalTo(_selectedGoodImage.mas_left).with.offset(3) ;
        make.centerY.equalTo(_selectedGoodDetailBtn.mas_centerY);
        
    }];
    [_selectedGoodDetailBottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_selectedGoodDetailBtn.mas_bottom) ;
        
        make.right.equalTo(_selectedGoodDetailBtn.mas_right).with.offset(-10);
        make.height.equalTo(@0.5);
        make.left.equalTo(_selectedGoodDetailBtn.mas_left).with.offset(10);
        
    }];


    [_specTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@0);
        make.left.equalTo(_specParentView.mas_left);
        make.right.equalTo(_specParentView.mas_right);
        make.top.equalTo(_specParentView.mas_bottom);
    }];




}
- (void)showAlertMessage:(NSString *)msg
{
    _alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [_alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:0.5f];
}
- (void)hideAlert
{
    if (_alt != nil)
    {
        [_alt dismissWithClickedButtonIndex:0 animated:YES];
        _alt = nil;
    }
}

@end
